package com.freedom.admin.application.service.query;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freedom.admin.application.converter.PermissionConverter;
import com.freedom.admin.domain.repository.PermissionRepository;
import com.freedom.admin.infrastructure.persistence.pojo.bo.PermissionBO;
import com.freedom.admin.infrastructure.persistence.pojo.query.PermissionPageQuery;
import com.freedom.admin.infrastructure.persistence.pojo.vo.perm.PermissionPageVO;
import com.freedom.admin.infrastructure.persistence.pojo.vo.perm.PermissionVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PermissionQueryService {

    private final PermissionRepository permissionRepository;

    private final PermissionConverter permissionConverter;

    public Page<PermissionPageVO> queryPermissionPage(PermissionPageQuery queryParams) {
        Page<PermissionBO> permissionBOPage = permissionRepository.queryPermissionPage(queryParams);
        return permissionConverter.pageVO(permissionBOPage);
    }

    public List<PermissionVO> queryPermissions(Integer menuId) {
        List<PermissionBO> permissionVOList = permissionRepository.queryPermissions(menuId);
        return permissionConverter.toVO(permissionVOList);
    }

    public PermissionVO findPermissionDetail(Integer permissionId) {
        PermissionBO permissionBO = permissionRepository.findPermissionById(permissionId);
        return permissionConverter.toVO(permissionBO);
    }
}
